package com.vae.goods.controller;

import com.vae.goods.service.SpuService;
import com.vae.mall.common.response.RespResult;
import com.vae.mall.goods.api.aggregate.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品管理controller
 * @author vae
 * @since 1.0
 */
@RestController
@RequestMapping("/spu")
public class SpuController {

    @Autowired
    private SpuService spuService;

    /***
     * 添加商品
     */
    @PostMapping(value = "/save")
    public RespResult save(@RequestBody Product product){
        //保存
        spuService.saveProduct(product);
        return RespResult.ok();
    }
    /***
     * 根据spu的ID查询Product
     * @param id  spu的id
     */
    @GetMapping(value = "/product/{id}")
    public RespResult<Product> one(@PathVariable(value = "id")String id){
        Product product = spuService.findBySpuId(id);
        return RespResult.ok(product);
    }

}